// 上传文件
const upload = async function(action, header, {
  // #ifdef APP-PLUS || H5
  files,
  // #endif
  // #ifdef H5
  file,
  // #endif
  // #ifdef MP-ALIPAY
  fileType,
  // #endif
  filePath,
  name,
  formData
}) {
  return new Promise((resolve, reject) => {
    uni.showLoading({
      mask: true,
      title: '上传中'
    });
    let data = {
      url: action,
      header,
      name: 'file',
      complete: function() {
        uni.hideLoading();
      },
      success: uploadFileRes => {
        try {
          var res = uploadFileRes.data;
          if (uni.$u.test.jsonString(res)) {
            resolve(JSON.parse(res))
          }
          if (uni.$u.test.object(res)) {
            resolve(res)
          }
        } catch (e) {
          reject(uploadFileRes.data);
        }
      },
      fail: (e) => {
        reject(e);
      }
    };
    // #ifdef H5
    //有文件对象，一般是H5
    if (file) {
      data.file = file;
    }
    // #endif
    //文件路径
    if (filePath) {
      data.filePath = filePath;
    }
    uni.uploadFile(data);
  })
}

export const goUpload = async (action, header, params = {}) => await upload(action, header, params)